import { Injectable } from '@angular/core';
import { Observable } from '../../../../node_modules/rxjs';
import { HttpClient, HttpParams } from '@angular/common/http';

@Injectable()
export class CourseService {

  constructor(private http: HttpClient) {}

  create4CourseDetail(inJson: any, courseId: string): Observable<any> {
    const url = "/courseDetail/create?courseId=" + courseId;
    return this.http.post(url, inJson);
  }

  del4CourseDetail(inJson: any): Observable<any> {
    const url = "/courseDetail/delete";
    let params = new HttpParams()
      .set('id', inJson);
    return this.http.get(url, {params});
  }

  edit4CourseDetail(inJson: any): Observable<any> {
    const url = "/courseDetail/edit";
    return this.http.post(url, inJson);
  }

  queryCourseDetailById(id: any): Observable<any> {
    const url = "/courseDetail/getCourseListByCourseId";
    let params = new HttpParams()
      .set('courseId', id)
      .set('employeeId', null);

    return this.http.get(url, { params: params });
  }

  // 新建
  create(inJson: any, employeeId: number): Observable<any> {
    const url = "/course/create?createrId=" + employeeId;
    return this.http.post(url, inJson);
  }

  // 查询
  query(paging: any): Observable<any> {
    const url = "/course/query";
    let params = new HttpParams()
      .set('condition', "{}")
      .set('page', paging.pi)
      .set('results', paging.ps);
    // let params = new HttpParams()
    //   .set('courseId', "id")
    //   .set('employeeId', null);

    return this.http.get(url, { params: params });
  }

  // 删除
  del(inJson: any): Observable<any> {
    const url = "/course/delete";
    let params = new HttpParams()
      .set('id', inJson);
    return this.http.get(url, {params});
  }

  // 编辑
  edit(inJson: any): Observable<any> {
    const url = "/course/edit";
    return this.http.post(url, inJson);
  }

  getValueListByParentCode(code: any): Observable<any> {
      const url = "/valuelist/queryByParentCode";
      let params = new HttpParams()
      .set('code', code);

      return this.http.get(url, { params: params });
      }

}
